package com.nbx.app.zeuscmdport;

import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.view.MotionEvent;

public class Render06 extends RenderBase {

	private int mColorType = 0;
	public Render06(Context context) {
		super(context);
	}

	float xrot = 0.0f;
	float yrot = 0.0f;
	private float square[] = {
			0.25f, 0.25f, 0.0f, 
			0.75f, 0.25f, 0.0f, 
			0.25f, 0.75f, 0.0f, 
			0.75f, 0.75f, 0.0f};

	private FloatBuffer mTexCoords;
	
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		mTexCoords = createFloatBuffer(square);

		gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);

		/*gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);*/

		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mTexCoords);
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	}

	public void onSurfaceChanged(GL10 gl, int width, int height) {

		gl.glViewport(0, 0, width, height);
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);		
	}

	public void onDrawFrame(GL10 gl) {

		switch(mColorType){
			case 0: gl.glColor4f(0, 1, 1, 1); break;
			case 1: gl.glColor4f(1, 0, 1, 1); break;
			case 2: gl.glColor4f(1, 1, 0, 1); break;
			case 3: gl.glColor4f(0, 0, 1, 1); break;
			case 4: gl.glColor4f(0, 1, 0, 1); break;
			case 5: gl.glColor4f(1, 0, 0, 1); break;
			case 6: gl.glColor4f(0, 0, 0, 1); break;
		}
		
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
	}
	
	@Override
	public boolean handleTouchEvent(MotionEvent event) {
		if(mColorType < 6){
			mColorType ++;
		}else{
			mColorType = 0;
		}
		return true;
	}	
}